/************************************************************************/
/* Game                                                                 */
/************************************************************************/
#include "Game/Game Objects/Cloud.h"

namespace TD_Game {

	/************************************************************************/
	/* Default definitions                                                  */
	/************************************************************************/
	const string Cloud::cloudImage = "Game Objects/cloud.png";
	const float Cloud::cloudSpeed = 0.25/60.0;

	Cloud::Cloud() : Tile() {

	}

	Cloud::Cloud(const Coord2D &g_position) : Tile(g_position) {
		m_pImage = TD_Resources::ResourceManager::loadImage(cloudImage, Color::BLACK);
		SDL_SetAlpha(m_pImage->getSurface(), SDL_SRCALPHA | SDL_RLEACCEL, 200);
		srand ( Timer::getSystemTime() );
		m_yDir = 1;
		m_fX = 0;
		m_fY = 0;
	}

	Cloud::~Cloud() {
		//mimi, no big deal
	}

	void Cloud::render(SDL_Surface *const g_destSurface, unsigned int deltaTime) {
		if(rand() % 2) {
			m_fX += deltaTime * cloudSpeed ;
			m_fY += (deltaTime * cloudSpeed * m_yDir) / 4;
		} else {
			m_fX += (deltaTime * cloudSpeed) / 2;
			m_fY += deltaTime * cloudSpeed * m_yDir;
		}

		if(m_fX >= 1) {
			++m_position.x;
			m_fX = 0;
		}

		if(m_fY >= 1 || m_fY <= -1) {
			m_position.y += m_fY;
			m_fY = 0;
			if(rand() % 2)
				m_yDir = -m_yDir;
		}
		blitSurface(g_destSurface);
	}
}